layui.config({
    base: '../../static/layuiadmin/' //静态资源所在路径
}).extend({
    index: 'lib/index' //主入口模块
}).use(['form','index', 'useradmin', 'table','layedit'], function(){
    var table = layui.table,layer = layui.layer; //独立版的layer无需执行这一句
    var layedit = layui.layedit;
    var form=layui.form;
    //监听提交
    form.on('submit(demo1)', function(data){
        var data=data.field;
        var regEmail = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/
        if(data.sendTo==null||data.sendTo==''){
            layer.msg("请输入收件邮箱", {icon: 2,time:2000,shade:0.2});
            return false;
        }else if(!regEmail.test(data.sendTo)){
            layer.msg("请输入正确的邮箱", {icon: 2,time:2000,shade:0.2});
            return false;
        }else if(data.title==null||data.title==''){
            layer.msg("请输入邮件标题", {icon: 2,time:2000,shade:0.2});
            return false;
        }else if(data.detail==null||data.detail==''){
            layer.msg("请输入邮件内容", {icon: 2,time:2000,shade:0.2});
            return false;
        }
        var loadindex = layer.load(1, {
            shade: [0.3, '#000000'] //0.1透明度的白色背景
        });
        $.ajax({
            url:"/email/sendQuestion",
            type:"post",
            data:data,
            success:function () {
                form.val('example', {
                    "sendTo": undefined // "name": "value"
                    ,"title": undefined
                    ,"detail": undefined
                });
                layer.close(loadindex);
                layer.msg("邮件发送成功", {icon: 1});
                layer.close(index);
            }
        });
        return false;
    });


    $("#submitCode").click(function () {
        var phone = $("#sendCode").val();
        $.ajax({
            url:"/sendSms",
            type:"get",
            data:{phone:phone},
            success:function (res) {
                if (res.code == 0){
                    console.log(res.data.code[0])
                    $("#code").val(res.data.code[0]);
                    layer.msg("验证码发送成功", {icon: 1});
                }
            }
        });
        return false;
    })
});